<%@ page language="java" pageEncoding="utf-8"%>
<%@ include file="../includes/importer.jsp"%>
<!doctype html>
<html>
<head>
<ht:head />
<script src="<spring:url value="/static/js/uploadify/jquery.uploadify.js"/>" type="text/javascript" charset="utf-8"></script>
<link href="<spring:url value="/static/js/uploadify/uploadify.css"/>" rel="stylesheet" type="text/css" />
<script type="text/javascript">

$().ready(function() {
	$("#radio-vt").click(function() {
		$("#orderPrice").show();
		$("#orderItemNum").hide();
		$("input[name=orderItemNum]").val("");
		$("input[name=freeItemNum]").val("");
	});
	$("#radio-vd").click(function() {
		$("#orderItemNum").show();
		$("#orderPrice").hide();
		$("input[name=orderTotalPrice]").val("");
		$("input[name=freeTotalPrice]").val("");
	});
  	
	//上传封面logo图片
	$("#uploadPropertyPic").uploadify({
		height        : 25,
		removeCompleted:true,
		swf           : G_CTX_ROOT + '/static/js/uploadify/uploadify.swf',
		width         : 90,
		uploader:  "${ctx}/imgUpload/activities/${uploadImgId};jsessionid=<%=request.getRequestedSessionId()%>",
		onUploadSuccess:function(file, data, response){
				var timestamp = new Date().getTime();
				var path = data+"?d="+timestamp
				$("#logoImg").attr("src",path);
				$("#imgPath").val(data);
		}
	});
	
	
});

	// -- 表单提交事件
	function check() {
		var imgPath = $("#imgPath").val();
		if(!imgPath) {
			simpleWarn("请上传活动图片！", null);
			return false;
		}
		var type = $("input[name='type']:checked").val();
		if(type == 1) {
			var orderItemNum = new Number($("input[name=orderItemNum]").val());
			var freeItemNum =  new Number($("input[name=freeItemNum]").val());
			if(orderItemNum <= freeItemNum) {
				simpleWarn("免件数须小余订单件数!", null);
				return false;
			}
		}
		if(type == 2) {
			var orderTotalPrice = new Number($("input[name=orderTotalPrice]").val());
			var freeTotalPrice =  new Number($("input[name=freeTotalPrice]").val());
			if(orderTotalPrice <= freeTotalPrice) {
				simpleWarn("免额须小余订单金额!", null);
				return false;
			}
		}
	} 
	
</script>

</head>
<body>
	<div id="content">
		<!-- forms -->
		<div class="box">
			<!-- box / title -->
			<div class="title">
				<h5>
					更新活动
				</h5>
			</div>
					<br>
			<!-- end box / title -->
			<form:form method="post" id="fm" onsubmit="return check()" commandName="ac" htmlEscape="true" acceptCharset="utf-8" cssClass="required-validate">
				<div class="form">
					<div class="fields">
						<input type="hidden" name="id" value="${ac.id }">
						<div class="field">
							<div class="label">
								<label for="name" class="req">活动名称：</label>
							</div>
							<div class="input">
								<form:input path="name" cssClass="required" maxlength="20"/>
							</div>
						</div>
						
						<div class="field">
							<div class="label">
								<label class="req">活动类型：</label>
							</div>
							 <div class="radios">
								<div class="radio">
									<input type="radio" id="radio-vt" name="type" class="validate-one-required" value="2"  
									<c:if test="${ac.type==2 }">checked</c:if> />
									<label for="radio-vt">满额减</label>
									<input type="radio" id="radio-vd" name="type" class="validate-one-required" value="1"
									<c:if test="${ac.type==1 }">checked</c:if> />
									<label for="radio-vd">满件赠 </label> 
								</div>
								<span class="error" id="advice-validate-one-required-sendCodeChannel"style="display:none"></span>
								<span class="error" id="advice-validate-one-required-radio-verify"></span>
							</div>
						</div>
						
						<div id="orderPrice" <c:if test="${ac.type==1 }">style="display:none;"</c:if> >
							<div class="field">
								<div class="label">
									<label for="orderTotalPrice" class="req">订单满额：</label>
								</div>
								<div class="input">
									<form:input path="orderTotalPrice" cssClass="required validate-number min-value-0.1" maxlength="10" />
								</div>
							</div>
							
							<div class="field">
								<div class="label">
									<label for="freeTotalPrice" class="req">订单减额：</label>
								</div>
								<div class="input">
									<form:input path="freeTotalPrice" cssClass="required validate-number min-value-0.1" maxlength="10" />
								</div>
							</div>
						</div>
						
						<div id="orderItemNum" <c:if test="${ac.type==2 }">style="display:none;"</c:if> >
							<div class="field">
								<div class="label">
									<label for="orderItemNum" class="req">订单满件数：</label>
								</div>
								<div class="input">
									<form:input path="orderItemNum" cssClass="required validate-number min-value-1 int-range-1-9999999" maxlength="200" />
								</div>
							</div>
							
							<div class="field">
								<div class="label">
									<label for="freeItemNum" class="req">免赠件数：</label>
								</div>
								<div class="input">
									<form:input path="freeItemNum" cssClass="required validate-number min-value-1 int-range-1-9999999" maxlength="200" />
								</div>
							</div>
						</div>
						
						<div class="field">
							<div class="label">
								<label for="inputStartTime"  class="req">活动开始时间：</label>
							</div>
							<div class="input">
								<input type="text"  name="inputStartTime"  id="inputStartTime" class="txt required" readOnly  style="width:170px;"  value="${ac.startTime }
								     onfocus="WdatePicker({vel:'startTime',dateFmt:'yyyy-MM-dd HH:mm:ss',realFullFmt:'yyyyMMddHHmmss',maxDate:'#F{$dp.$D(\'inputEndTime\')}')" />
								 <input type="hidden" name="startTime" id="startTime" value="${ac.startTime }"/>
							</div>
						</div>
						
						<div class="field">
							<div class="label">
								<label for="inputEndTime"  class="req">活动结束时间：</label>
							</div>
							<div class="input">
								 <input type="text"   name="inputEndTime"  id="inputEndTime" class="txt required" readOnly style="width:170px;" value="${ac.endTime }"
								 	 onfocus="WdatePicker({vel:'endTime',dateFmt:'yyyy-MM-dd HH:mm:ss',realFullFmt:'yyyyMMddHHmmss',minDate:'#F{$dp.$D(\'inputStartTime\')}',maxDate:'2050-10-01'})" />
								 <input type="hidden" name="endTime" id="endTime" value="${ac.endTime }"/>
							</div>
						</div>
						
					<div class="field">
                   		 <div class="label">
                    	<label for="uploadfile" class="req">活动LOGO：</label>
	                    </div>
	                    <div class="input">
	                    	<img src="${ac.imgPath }" id="logoImg" style="background: #ECE9D8" height="95" width="130">
	                    </div>
	                    <div class="input" style="width: 120px;" >
	                    	<input type="file" id="uploadPropertyPic" name="uploadPropertyPic" style="display:none; margin-left: 10px;"  size="0" />
	                    	<input type="hidden" name="imgPath" id="imgPath" value="${ac.imgPath }" cssClass="required">
	                   	</div>
	                    <div class="img-size-desc" style="margin-left: 79px; color: red;">建议图片大小为 800*800 或 600*600</div>
                	</div>
						
						<div class="field">
							<div class="label label-textarea">
								<label for="explain">活动介绍：</label>
							</div>
							<div class="input">
								<ht:xheditor/>
								<form:textarea path="explain" cols="50" rows="8" cssClass="cxheditor max-length-300"/>
							</div>
						</div>
						
						<div class="buttons">
							<div class="highlight">
								<input type="submit" name="submit.highlight" value="提交" />
							</div>
							<input type="reset" name="reset" value="重置" />
							<input type="button" class="common_btn" onclick="history.back();" value="返回" />
						</div>
					</div>
				</div>
			</form:form>
		</div>
		<!-- end forms -->
	</div>
</body>
</html>